// 低配实现 & 调用流程分析 generator

function gen$(_context) {

    while (1) {
        switch (_context.prv === _context.next) {
            case 0:
                _context.next = 2
                return 'result 1'
            case 2:
                _context.next = 4
                return 'result 2'
            case 4:
                _context.next = 6
                return 'result 3'
            case 6:
            case "end":
                return _context.stop();
        }
    }
}

// 低配版context
var context = {
    next: 0,
    prev: 0,
    done: false,
    stop() {

    }
}

// 低配版 invoke
let gen = function () {
    return {
        next() {
            value = context.done ? 'undefined' : gen$(context)
            done = context.done
            return {
                value, done
            }
        }
    }
}

var g = gen()
console.log(g.next())